#include <cassert>
#include "nms.h"
#include "nonzero.h"

int main() {
    // nonzero
    std::cout << "Nonzero" << std::endl;
    float scores[20] = {
            0.0000, 0.2682, 0.0000, 0.0000, 0.0000, 0.1341, 0.0000, 0.3964,
            0.0000, 0.1323, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0185,
            0.1977, 0.3000, 0.0000, 0.0000
    };
    float boxes[80] = {
            68.1609, 91.5194, 39.7100, 87.4156, 41.9408, 55.2907, 95.2738, 3.6165,
            18.5231, 37.3417, 30.5100, 93.2000, 17.5910, 26.9834, 15.0680, 3.1720,
            20.8130, 92.9799, 72.3109, 74.2336, 52.6296, 24.3658, 58.4592, 3.3153,
            13.8717, 24.2235, 81.5469, 79.3161, 27.8252, 48.1959, 81.9780, 99.7067,
            69.8441, 56.7546, 83.5243, 20.5599, 59.3172, 11.2347, 15.3457, 24.1708,
            72.6236, 70.1080, 20.3824, 65.1054, 77.4486, 43.6891, 51.9091, 61.5852,
            81.0188, 98.0097, 11.4688, 31.6765, 69.6505, 91.4275, 93.5104, 94.1178,
            59.9507, 6.5209, 54.5996, 18.7197, 3.4023, 94.4246, 88.0180, 0.1236,
            59.3586, 41.5770, 41.7719, 27.1122, 69.2278, 20.3848, 68.3296, 75.2854,
            85.7936, 68.6956, 0.5132, 17.5652, 74.9658, 60.4651, 10.9958, 21.2090
    };
    cudaError_t status = nonzero(scores, boxes, 20);
    assert(status == cudaSuccess);

    // nms
    std::cout << "========================================" << std::endl;
    std::cout << "NMS" << std::endl;
    float nms_scores[100] = {
            0.496257, 0.768222, 0.088477, 0.132030, 0.307423, 0.634079, 0.490093,
            0.896445, 0.455628, 0.632306, 0.348893, 0.401717, 0.022326, 0.168859,
            0.293888, 0.518522, 0.697668, 0.800011, 0.161029, 0.282269, 0.681609,
            0.915194, 0.397100, 0.874156, 0.419408, 0.552907, 0.952738, 0.036165,
            0.185231, 0.373417, 0.305100, 0.932000, 0.175910, 0.269834, 0.150680,
            0.031720, 0.208130, 0.929799, 0.723109, 0.742336, 0.526296, 0.243658,
            0.584592, 0.033153, 0.138717, 0.242235, 0.815469, 0.793161, 0.278252,
            0.481959, 0.819780, 0.997067, 0.698441, 0.567546, 0.835243, 0.205599,
            0.593172, 0.112347, 0.153457, 0.241708, 0.726237, 0.701080, 0.203824,
            0.651054, 0.774486, 0.436891, 0.519091, 0.615852, 0.810188, 0.980097,
            0.114688, 0.316765, 0.696505, 0.914275, 0.935104, 0.941178, 0.599507,
            0.065209, 0.545996, 0.187197, 0.034023, 0.944246, 0.880180, 0.001236,
            0.593586, 0.415770, 0.417719, 0.271122, 0.692278, 0.203848, 0.683296,
            0.752854, 0.857936, 0.686956, 0.005132, 0.175652, 0.749658, 0.604651,
            0.109958, 0.212090
    };
    float nms_boxes[400] = {
            84.099167, 54.199768, 109.975769, 113.182022,
            16.185165, 6.655640, 40.212318, 68.175880,
            -27.539425, 42.663528, 32.279617, 55.539055,
            -16.815411, -24.216066, 41.509518, 47.080399,
            12.349243, 35.654221, 82.140793, 79.360283,
            25.018175, 58.522728, 34.028793, 100.815025,
            -14.109650, 79.490433, 53.255737, 111.246582,
            49.775463, -33.813210, 118.754517, 49.484917,
            25.609573, 27.009584, 49.501991, 77.502678,
            21.957581, 34.899269, 92.632530, 88.818161,
            42.533127, 24.873371, 96.709702, 81.116638,
            20.257256, 46.694740, 30.949871, 100.624153,
            -40.274189, -27.163177, 44.349300, 67.892509,
            -2.210262, -2.705744, 77.177277, 53.994408,
            -4.167023, -3.819093, 69.183685, 21.856926,
            35.081451, 57.185848, 43.647034, 64.189796,
            -32.513531, 6.564301, 67.366959, 88.303764,
            78.073387, 10.078922, 93.511696, 79.641052,
            7.510422, -4.303818, 95.268799, 95.676926,
            13.259197, 37.423130, 106.978943, 126.160828,
            78.093796, 65.526337, 116.630829, 97.979248,
            51.944458, 7.374428, 142.996902, 85.393410,
            -4.871601, -21.179291, 15.039450, 73.771568,
            46.966293, 11.047489, 121.124222, 88.304260,
            15.817091, -20.488085, 34.478271, 43.856911,
            -13.028542, -36.734322, 19.443336, 52.333504,
            19.356676, 42.687492, 60.359650, 112.153114,
            47.591507, -33.858299, 106.472595, 37.415108,
            64.684792, -26.314758, 97.693413, 48.063812,
            31.891258, -0.920008, 46.967712, 60.372742,
            32.284035, 39.846306, 48.454437, 40.519424,
            0.208897, -37.908646, 10.056108, 51.564857,
            3.650135, 2.191216, 80.701920, 99.102005,
            -17.741776, 66.161095, 72.314285, 71.508827,
            -2.942142, 25.665201, 12.936303, 67.586075,
            85.206779, -12.754513, 102.735161, 71.965317,
            89.050346, 55.305225, 101.249962, 80.910156,
            4.029238, 70.828506, 5.724669, 92.441223,
            -1.331657, -17.789345, 89.792213, 73.148659,
            47.086723, -34.707939, 132.878601, 53.898422,
            8.135582, 20.933138, 102.594910, 58.129990,
            49.705582, 16.683964, 121.705688, 111.230484,
            40.754799, 17.666035, 107.295738, 117.649857,
            0.009693, -1.056480, 75.942841, 80.025932,
            -7.454268, 40.096519, 25.046125, 114.087898,
            61.826241, 65.181679, 117.571571, 103.240807,
            3.823832, 41.257912, 25.638338, 63.202080,
            8.990314, -19.307465, 20.516273, 64.259048,
            -21.908556, 44.932568, 63.638008, 89.241928,
            9.671492, 4.586506, 30.737192, 93.231781,
            11.116180, 55.372803, 93.090630, 109.089508,
            -0.992620, -32.301807, 25.400616, 63.650585,
            -14.256596, 78.975311, 56.190441, 91.018036,
            -16.900322, 48.190094, 80.953819, 136.158783,
            52.192646, 17.277435, 83.968102, 95.385162,
            38.832527, 19.033779, 60.423073, 61.198063,
            10.045784, 12.549789, 102.500847, 64.615746,
            42.329132, 39.735477, 56.968224, 73.023834,
            -7.324126, 3.616648, 29.103615, 43.970207,
            62.982117, -38.698074, 117.767151, 57.543404,
            20.071182, 89.897934, 72.748199, 109.025940,
            41.780495, 14.428474, 94.343208, 88.402832,
            -30.731503, 72.617363, 44.070507, 76.920433,
            -6.140477, 29.385399, 34.912403, 42.228172,
            18.891321, 8.588295, 47.557045, 76.602966,
            43.300167, 56.947208, 57.793659, 125.533554,
            10.022491, 68.144928, 102.461395, 121.424347,
            72.247818, 2.346426, 88.923431, 34.432182,
            41.966099, 8.713148, 102.884308, 20.597246,
            -8.611515, 62.402870, 66.229004, 67.009392,
            65.541939, 86.802917, 67.477272, 88.219894,
            13.975788, 8.269222, 53.832623, 91.890869,
            74.403152, -44.134285, 77.079208, 47.425072,
            71.149605, -23.668222, 101.148460, 40.975983,
            24.549051, 39.042137, 76.829201, 43.956184,
            -22.066875, 18.147465, 69.399582, 95.069641,
            41.496048, -2.246284, 141.195831, 73.014328,
            11.817020, -14.356535, 28.813572, 77.372650,
            -25.901028, 35.714283, 26.786194, 109.425110,
            21.032543, -1.176352, 30.941086, 34.442322,
            20.741869, 63.485115, 21.647989, 94.010490,
            46.085403, 83.005135, 106.871964, 93.747047,
            35.167049, -5.118156, 101.105255, 71.722183,
            7.544859, 56.498585, 64.510323, 73.044418,
            85.484734, 46.307526, 96.718742, 80.881691,
            -9.631222, -23.163782, 62.316685, 76.156044,
            -36.649178, 38.617630, 42.102272, 82.987167,
            -11.824535, 4.947782, 55.706287, 5.894637,
            90.196358, -19.135759, 97.491295, 54.194641,
            33.472305, 27.297283, 55.151543, 101.352066,
            44.241219, 3.738686, 58.944611, 28.973141,
            5.176138, 51.808102, 13.991690, 127.900131,
            35.689308, 47.241196, 80.594559, 135.721252,
            -7.233837, 25.894203, 73.709778, 103.561333,
            12.762285, 30.505894, 64.370094, 65.046997,
            -0.016418, 38.587532, 39.112000, 95.232567,
            28.415558, 41.483318, 103.201035, 56.453823,
            -7.227055, -3.103239, 84.736832, 41.460258,
            80.525879, 1.305241, 88.628601, 24.252350,
            23.362835, -14.675854, 117.603714, 81.050507
    };
    cudaError_t nms_status = nms(nms_boxes, nms_scores, 100, 0.3);
    assert(nms_status == cudaSuccess);
    return 0;
}
